package org.vaadinetherealintegration;

import org.vaadinetherealintegration.client.VMyComponent;

import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
import com.vaadin.ui.AbstractComponent;


/**
 * Server side component for the VMyComponent widget.
 * 
 * @author Jesus R Martinez (jesusrmartinez51@gmail.com)
 */
@com.vaadin.ui.ClientWidget(VMyComponent.class)
public class MyComponent extends AbstractComponent {

    private String command;
	private String params;
	
	public MyComponent(String initialCommand){
		command = VMyComponent.EXAMPLE_NUMBER;
		params = initialCommand;
	}

	public MyComponent() {
	}

	@Override
    public void paintContent(PaintTarget target) throws PaintException {
        super.paintContent(target);

        System.out.println("Paint Content " + command + " params " + params);
        if(command!=null){
        	target.addAttribute(command, params);
        }
    }
    
    public void fireEvent(String command, String params){
    	System.out.println("Fire event " +command + " params " + params);
    	this.command = command;
    	this.params = params;
    	
    	requestRepaint();
    }

}
